package com.example.design.limit;

import java.util.concurrent.Callable;

public class PriorityTask<T> implements Callable<T>, Comparable<PriorityTask<T>> {

    private int priority;

    private Callable<T> callable;

    public PriorityTask(int priority, Callable<T> callable) {
        this.priority = priority;
        this.callable = callable;
    }

    @Override
    public T call() throws Exception {
        return callable.call();
    }

    @Override
    public int compareTo(PriorityTask<T> other) {
        return Integer.compare(this.priority, other.priority);
    }
}
